package com.chiyoyo.rabbitmq.framework.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * @author chil
 * 基础发送MQ基类
 */
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class RabbitMqModel<T> {

    /**
     * 消息体
     */
    private T body;
    /**
     * 交换机
     */
    private String exchange;
    /**
     * 路由规则
     */
    private String routingKey;
    /**
     * 设置头部属性
     */
    private Map<String, Object> headers;

    /**
     * 消息类型
     */
    private String contentType;

    /**
     * 虚拟主机
     */
    private String virtualHost;

    /**
     * 消息是否持久
     */
    private Boolean messagePersistent = true;

    /**
     * 只发送消息体
     */
    private Boolean sendOnlyBody = false;

    /**
     * RabbitMqModel类的构造函数，用于创建一个RabbitMqModel对象
     *
     * @param exchange 交换机名称
     * @param body     消息体
     */
    public RabbitMqModel(String exchange, T body) {
        this.body = body;
        this.exchange = exchange;
    }

    /**
     * RabbitMqModel类的构造函数
     *
     * @param exchange   交换机名称
     * @param routingKey 路由键
     * @param body       消息体
     */
    public RabbitMqModel(String exchange, String routingKey, T body) {
        this.body = body;
        this.exchange = exchange;
        this.routingKey = routingKey;
    }

    /**
     * RabbitMqModel的构造函数
     *
     * @param exchange          交换机名称
     * @param routingKey        路由键
     * @param body              消息体
     * @param messagePersistent 是否持久化消息
     */
    public RabbitMqModel(String exchange, String routingKey, T body, boolean messagePersistent) {
        this.body = body;
        this.exchange = exchange;
        this.routingKey = routingKey;
        this.messagePersistent = messagePersistent;
    }
}
